home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / DATETIME / MTIMSTOP / MTIMESTO.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-20  |  4KB  |  132 lines

  1. {----------------------------------------------------------------------
  2.  
  3.   Time Stop - very simple component, that can be used to stop
  4.   application to run after specified date.
  5.  
  6.   Copyright (c) 1996 Ahto Tanner, Moon Software. No Rights Reserved.
  7.   Please read mTimeStop.txt for more information.
  8.  
  9.   History:
  10.  
  11.   1.1 October 20, 1996
  12.       - added OnExpire event,
  13.         created by Cezar Goncalves Lenci (sintesis@dglnet.com.br)
  14.       - added ShowExpireMessage property. You can turn default message off and
  15.         use OnExpire event for custom code/messagebox.
  16.  
  17.   1.0 September 07, 1996
  18.       - initial version
  19.  
  20. -----------------------------------------------------------------------}
  21.  
  22. unit mTimeStop;
  23.  
  24. interface
  25.  
  26. uses
  27.    SysUtils, Classes, Dialogs;
  28.  
  29. type
  30.    TmTimeStop = class(TComponent)
  31.  
  32.    private
  33.       FDay, FMonth, FYear: integer;
  34.       FMessage: string;
  35.       FShowExpireMessage: boolean;
  36.       FOnExpire: TNotifyEvent;
  37.       procedure SetDay( Value: integer );
  38.       procedure SetMonth( Value: integer );
  39.       procedure SetYear( Value: integer );
  40.  
  41.    protected
  42.       procedure Loaded; override;
  43.       
  44.    public
  45.       constructor Create( AOwner : TComponent ); override;
  46.  
  47.    published
  48.       property Day: integer read FDay write SetDay default 1;
  49.       property Month: integer read FMonth write SetMonth default 1;
  50.       property Year: integer read FYear write SetYear default 1996;
  51.       property Text: string read FMessage write FMessage;
  52.       property ShowExpireMessage: boolean read FShowExpireMessage write FShowExpireMessage;
  53.       property OnExpire : TNotifyEvent Read FOnExpire Write FOnExpire;
  54.  
  55. end;
  56.  
  57. procedure Register;
  58.  
  59. implementation
  60.  
  61. {-------------------------------------------------------------------------}
  62.  
  63. constructor TmTimeStop.Create( AOwner : TComponent );
  64. begin
  65.    inherited;
  66.    // set default properties
  67.    FDay := 1;
  68.    FMonth := 1;
  69.    FYear := 1996;
  70.    FShowExpireMessage := true;
  71.    FMessage := 'This version has expired. Please see readme.txt file on ' +
  72.       'how to obtain newer version.';
  73. end;
  74.  
  75. {-------------------------------------------------------------------------}
  76.  
  77. procedure TmTimeStop.SetDay( Value: integer );
  78. begin
  79.    if Value in [1..31] then
  80.       FDay := Value
  81.    else
  82.       ShowMessage( 'Day must be between 1 and 31 as you know.' );
  83. end;
  84.  
  85. {-------------------------------------------------------------------------}
  86.  
  87. procedure TmTimeStop.SetMonth( Value: integer );
  88. begin
  89.    if Value in [1..12] then
  90.       FMonth := Value
  91.    else
  92.       ShowMessage( 'Month must be between 1 and 12 as you know.' );
  93. end;
  94.  
  95. {-------------------------------------------------------------------------}
  96.  
  97. procedure TmTimeStop.SetYear( Value: integer );
  98. begin
  99.    if ( Value > 1995 ) AND ( Value < 3000 ) then
  100.       FYear := Value
  101.    else
  102.       ShowMessage( 'Year must be between 1996 and 3000.' );
  103. end;
  104.  
  105. {-------------------------------------------------------------------------}
  106.  
  107. procedure TmTimeStop.Loaded;
  108. begin
  109.    Inherited Loaded;
  110.    if NOT ( csDesigning in ComponentState ) then begin
  111.       if Date > EncodeDate( FYear, FMonth, FDay ) then begin
  112.          if FShowExpireMessage then begin
  113.             Beep;
  114.             ShowMessage( FMessage );
  115.          end;
  116.          if Assigned( FOnExpire ) Then FOnExpire( Self );
  117.          Halt;
  118.       end;
  119.    end;
  120. end;
  121.  
  122. {-------------------------------------------------------------------------}
  123.  
  124. procedure Register;
  125. begin
  126.    RegisterComponents( 'Moon', [ TmTimeStop ] );
  127. end;
  128.  
  129. {-------------------------------------------------------------------------}
  130.  
  131. end.
  132.